package com.fetch.spider;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.tinygroup.htmlparser.node.HtmlNode;
import org.tinygroup.parser.filter.FastNameFilter;
import org.tinygroup.tinyspider.Processor;

import com.download.download.MulThreadDownload;
import com.download.entity.DownloadInfo;
import com.download.utils.DownloadHelper;

public class ImgProcessor3 implements Processor {

    static String path = "F:"+File.separator+"fetchGirl2";
    @Override
    public void process(String url, HtmlNode node, Map<String, Object> parameters) throws Exception {
        FastNameFilter<HtmlNode> filter = new FastNameFilter<HtmlNode>(node);
        filter.setNodeName("img");
        List<HtmlNode> imgList = filter.findNodeList();
        for (HtmlNode img : imgList) {
            String imgUrl = img.getAttribute("src");
            downLoadImg(imgUrl,3);
        }
    }
    
    public void downLoadImg(String imgUrl, int threadCount){
        DownloadInfo downloadInfo = DownloadHelper.createDownloadInfo(imgUrl,null, path, threadCount);
        MulThreadDownload mulThreadDownload = new MulThreadDownload(downloadInfo);
        new Thread(mulThreadDownload).start();
    }
}
